#include"Stack.h"
#include<assert.h>
using namespace std;

Stack::Stack(int capacity)
	{
		int* tmp = (int*)malloc(sizeof(int) * capacity);
		if (tmp == nullptr)
		{
			perror("malloc fail");
		}
		_a = tmp;
		_size = 0;
		_capacity = 4;
	}
void Stack::Stackpush(int x)
	{
		_a[_size] = x;
		_size++;
	}
	int Stack::Stacktop()
	{
		assert(_a);
		return _a[_size - 1];
	}
	void Stack::Stackpop()
	{
		assert(_a);
		--_size;
	}
	Stack::~Stack()
	{
		free(_a);
		_a = nullptr;
		_size = _capacity = 0;
	}

